library(plyr)
library(dplyr)
library(tidyverse)
library(gsynth)
library(stargazer)

setwd("~/Dropbox/China Huawei Paper/Production Materials/Replication/")
master.data <- read.csv("dataFile_China_Huawei.csv"); head(master.data)

dat <- master.data

sub = dat[dat$v2x_polyarchy<=0.42,]
sub = sub[sub$cabb!="MNG",]
sub = sub[sub$cabb!="SSD",]
sub = sub[is.na(sub$v2smgovfilprc)==F & is.na(sub$v2x_polyarchy)==F & is.na(sub$pres.election)==F & is.na(sub$coup.attempts)==F & is.na(sub$successful.coups)==F,]
sub = sub[is.na(sub$pcGDPcur)==F & is.na(sub$GDPcur)==F & is.na(sub$electricitypc)==F,]
nrow(dat);nrow(sub)

sub$china.huawei.l1[is.na(sub$china.huawei.l1)==T & sub$year<=2017] <- 0

out1 <- lm(v2smgovfilprc ~ log(china.huawei.l1+1) + v2x_polyarchy + pres.election + coup.attempts + successful.coups + icews.protest + icews.repression + GDPcur + pcGDPcur + electricitypc + as.factor(cabb) + as.factor(year), data=sub)

out2 <- lm(v2smgovshut ~ log(china.huawei.l1+1) + v2x_polyarchy + pres.election + coup.attempts + successful.coups + icews.protest + icews.repression + GDPcur + pcGDPcur + electricitypc + as.factor(cabb) + as.factor(year), data=sub)

out3 <- lm(v2smgovsmmon ~ log(china.huawei.l1+1) + v2x_polyarchy + pres.election + coup.attempts + successful.coups + icews.protest + icews.repression + GDPcur + pcGDPcur + electricitypc + as.factor(cabb) + as.factor(year), data=sub)

out4 <- lm(v2smarrest ~ log(china.huawei.l1+1) + v2x_polyarchy + pres.election + coup.attempts + successful.coups + icews.protest + icews.repression + GDPcur + pcGDPcur + electricitypc + as.factor(cabb) + as.factor(year), data=sub)

stargazer(out1,out2,out3,out4
          ,title="OLS Models of Huawei Transfers and Digital Repression (Autocracies)"
          ,label="Table: OLS Autocracies"
          ,omit=c("cabb","year")
          ,add.lines=list(c("Country fixed effects",rep("$\\checkmark$",4)  ),
                            c("Year fixed effects",rep("$\\checkmark$",4)  ))
          , font.size="footnotesize"
          , dep.var.labels=c("Internet Filtering", "Internet Shutdowns","Social Media Monitoring", "Arrests for Political Content")
          ,covariate.labels=c("Huawei Transfers$_{t-1}$","Polyarchy","Presidential Election","Coup Attempts","Successful Coups","Protests","Repression","GDP","GDP Per Capita","Electricity Per Capita")
                          )

